'''

Case Type： 人为因素
Case Name： 修改pg_class表名称
Create At:  2020/10/12
@zou_jialiang0505328126
Descption: 1、新建表test_table
           2、更新pg_class中该表名称
           3、对该表做数据插入，查询操作

history：
created： 2020/10/12  created by @wan005
'''
import os
import unittest
from yat.test import Node
import time
from yat.test import macro
import sys
import datetime

sys.path.append(sys.path[0] + "/../")
from testcase.utils.Logger import Logger
from testcase.utils.Constant import Constant
from testcase.utils.Common import Common
from testcase.utils.CommonSH import *

logger = Logger()
common = Common()
commonshpri = CommonSH('PrimaryDbUser')

class ModifyConnection(unittest.TestCase):
    dbPrimaryUserNode = Node(node='PrimaryDbUser')
    dbPrimaryRootNode = Node(node='PrimaryRoot')    
    dbStandby1RootNode = Node(node='Standby1Root')    
    DB_INSTANCE_PATH = macro.DB_INSTANCE_PATH
    DB_ENV_PATH = macro.DB_ENV_PATH
    Constant = Constant()
    CFE_PATH = macro.CFE_PATH
    TPCC_PATH = macro.TPCC_PATH

    nodes_tuple = ('PrimaryDbUser', 'Standby1DbUser', 'Standby2DbUser')
    @RestartDbCluster(*nodes_tuple)
    def setUp(self):
        logger.info("-----------this is setup-----------")
        logger.info("-----------reliability_humanfactor001 start-----------")
        

    def test_modify_pidfile(self):
        logger.info("-----------create table--------------------")        
        result = commonshpri.executDbSql('create table reliability_humanfactor001(i int);')
        logger.info(result)
        self.assertIn(self.Constant.TABLE_CREATE_SUCCESS, result)
        
        logger.info("-----------update pg_class--------------------")        
        result = commonshpri.executDbSql('update pg_class set relname=\'reliability_humanfactor001_new\' where relname=\'reliability_humanfactor001\'')
        logger.info(result)
        self.assertIn("UPDATE", result)
        
        logger.info("--------insert data into reliability_humanfactor001 fail---------")
        result = commonshpri.executDbSql('insert into reliability_humanfactor001 values (1);')
        logger.info(result)
        self.assertIn(self.Constant.NOT_EXIST, result)
        logger.info("--------insert data into reliability_humanfactor001_new success---------")
        result = commonshpri.executDbSql('insert into reliability_humanfactor001_new values (1);')
        logger.info(result)
        self.assertIn("INSERT", result)

    def tearDown(self):
        logger.info('----------------this is tearDown-----------------------')
        logger.info("-----------drop table--------------------")        
        result = commonshpri.executDbSql('drop table if exists reliability_humanfactor001;')
        logger.info(result)
        result = commonshpri.executDbSql('drop table if exists reliability_humanfactor001_new;')
        logger.info(result)
        
       